options compress=YES;
libname manasi ''; 

* SORT BY (SAMPLE) SSN TO GET KID'S SIBLINGS ALL TOGETHER;
proc sort data=manasi.ssr_kids_wsiblings_wide out=manasi.ssr_kids_wsiblings_wide ;
	by hun;
run;

* RESHAPE LONG SO THAT THERE IS ONE RECORD PER KID-SIBLING PAIR 
	(ELIMINATE DUPLICATE SIBLINGS);
data manasi.ssr_kids_wsiblings_long;
	set manasi.ssr_kids_wsiblings_wide;

	array 	asibssn(1:7) 		sibssn1-sibssn7;
	array	acombpay_1983(1:7)	n_combpay_1983_1-n_combpay_1983_7;
	array	acombpay_1984(1:7)	n_combpay_1984_1-n_combpay_1984_7;
	array	acombpay_1985(1:7)	n_combpay_1985_1-n_combpay_1985_7;
	array	acombpay_1986(1:7)	n_combpay_1986_1-n_combpay_1986_7;
	array	acombpay_1987(1:7)	n_combpay_1987_1-n_combpay_1987_7;
	array	acombpay_1988(1:7)	n_combpay_1988_1-n_combpay_1988_7;
	array	acombpay_1989(1:7)	n_combpay_1989_1-n_combpay_1989_7;
	array	acombpay_1990(1:7)	n_combpay_1990_1-n_combpay_1990_7;
	array	acombpay_1991(1:7)	n_combpay_1991_1-n_combpay_1991_7;
	array	acombpay_1992(1:7)	n_combpay_1992_1-n_combpay_1992_7;
	array	acombpay_1993(1:7)	n_combpay_1993_1-n_combpay_1993_7;
	array	acombpay_1994(1:7)	n_combpay_1994_1-n_combpay_1994_7;
	array	acombpay_1995(1:7)	n_combpay_1995_1-n_combpay_1995_7;
	array	acombpay_1996(1:7)	n_combpay_1996_1-n_combpay_1996_7;
	array	acombpay_1997(1:7)	n_combpay_1997_1-n_combpay_1997_7;
	array	acombpay_1998(1:7)	n_combpay_1998_1-n_combpay_1998_7;
	array	acombpay_1999(1:7)	n_combpay_1999_1-n_combpay_1999_7;
	array	acombpay_2000(1:7)	n_combpay_2000_1-n_combpay_2000_7;
	array	acombpay_2001(1:7)	n_combpay_2001_1-n_combpay_2001_7;
	array	acombpay_2002(1:7)	n_combpay_2002_1-n_combpay_2002_7;
	array	acombpay_2003(1:7)	n_combpay_2003_1-n_combpay_2003_7;
	array	acombpay_2004(1:7)	n_combpay_2004_1-n_combpay_2004_7;
	array	acombpay_2005(1:7)	n_combpay_2005_1-n_combpay_2005_7;
	array	acombpay_2006(1:7)	n_combpay_2006_1-n_combpay_2006_7;
	array	acombpay_2007(1:7)	n_combpay_2007_1-n_combpay_2007_7;
	array	acombpay_2008(1:7)	n_combpay_2008_1-n_combpay_2008_7;
	array	acombpay_2009(1:7)	n_combpay_2009_1-n_combpay_2009_7;
	array	acombpay_2010(1:7)	n_combpay_2010_1-n_combpay_2010_7;
	array	acombpay_2011(1:7)	n_combpay_2011_1-n_combpay_2011_7;
	array	acombpay_2012(1:7)	n_combpay_2012_1-n_combpay_2012_7;
	
	do sib = 1 to 7;
		sibssn = asibssn(sib);
		n_combpay_1983 = acombpay_1983(sib);
		n_combpay_1984 = acombpay_1984(sib);
		n_combpay_1985 = acombpay_1985(sib);
		n_combpay_1986 = acombpay_1986(sib);
		n_combpay_1987 = acombpay_1987(sib);
		n_combpay_1988 = acombpay_1988(sib);
		n_combpay_1989 = acombpay_1989(sib);
		n_combpay_1990 = acombpay_1990(sib);
		n_combpay_1991 = acombpay_1991(sib);
		n_combpay_1992 = acombpay_1992(sib);
		n_combpay_1993 = acombpay_1993(sib);
		n_combpay_1994 = acombpay_1994(sib);
		n_combpay_1995 = acombpay_1995(sib);
		n_combpay_1996 = acombpay_1996(sib);
		n_combpay_1997 = acombpay_1997(sib);
		n_combpay_1998 = acombpay_1998(sib);
		n_combpay_1999 = acombpay_1999(sib);
		n_combpay_2000 = acombpay_2000(sib);
		n_combpay_2001 = acombpay_2001(sib);
		n_combpay_2002 = acombpay_2002(sib);
		n_combpay_2003 = acombpay_2003(sib);
		n_combpay_2004 = acombpay_2004(sib);
		n_combpay_2005 = acombpay_2005(sib);
		n_combpay_2006 = acombpay_2006(sib);
		n_combpay_2007 = acombpay_2007(sib);
		n_combpay_2008 = acombpay_2008(sib);
		n_combpay_2009 = acombpay_2009(sib);
		n_combpay_2010 = acombpay_2010(sib);
		n_combpay_2011 = acombpay_2011(sib);
		n_combpay_2012 = acombpay_2012(sib);
		output;
	end;

	drop 	sibssn1-sibssn7 
			n_combpay_1983_1-n_combpay_1983_7 
			n_combpay_1984_1-n_combpay_1984_7
			n_combpay_1985_1-n_combpay_1985_7
			n_combpay_1986_1-n_combpay_1986_7
			n_combpay_1987_1-n_combpay_1987_7
			n_combpay_1988_1-n_combpay_1988_7
			n_combpay_1989_1-n_combpay_1989_7
			n_combpay_1990_1-n_combpay_1990_7
			n_combpay_1991_1-n_combpay_1991_7
			n_combpay_1992_1-n_combpay_1992_7
			n_combpay_1993_1-n_combpay_1993_7
			n_combpay_1994_1-n_combpay_1994_7
			n_combpay_1995_1-n_combpay_1995_7
			n_combpay_1996_1-n_combpay_1996_7
			n_combpay_1997_1-n_combpay_1997_7
			n_combpay_1998_1-n_combpay_1998_7
			n_combpay_1999_1-n_combpay_1999_7
			n_combpay_2000_1-n_combpay_2000_7
			n_combpay_2001_1-n_combpay_2001_7
			n_combpay_2002_1-n_combpay_2002_7
			n_combpay_2003_1-n_combpay_2003_7
			n_combpay_2004_1-n_combpay_2004_7
			n_combpay_2005_1-n_combpay_2005_7
			n_combpay_2006_1-n_combpay_2006_7
			n_combpay_2007_1-n_combpay_2007_7
			n_combpay_2008_1-n_combpay_2008_7
			n_combpay_2009_1-n_combpay_2009_7
			n_combpay_2010_1-n_combpay_2010_7
			n_combpay_2011_1-n_combpay_2011_7
			n_combpay_2012_1-n_combpay_2012_7
			;	
run;

* ELIMINATE DUPLICATE SIBLINGS AND OWN RECORD;
data manasi.ssr_kids_wsiblings_long;
	set manasi.ssr_kids_wsiblings_long;
	
	* Delete missing sibs and own record;
	if sibssn=. or sibssn=hun then delete;

	* Drop variables;
	drop frompar fromkids;

	* Create indicator for whether sibling was on program;
	array combpay(1983:2012) n_combpay_1983-n_combpay_2012;
	array onssi(1983:2012) n_onssi_1983-n_onssi_2012;

	do i = 1983 to 2012;
		if combpay(i)>0 then onssi(i)=1;
			else onssi(i)=0;
	end;

run;

* Eliminate duplicate siblings;
proc sort data=manasi.ssr_kids_wsiblings_long out=manasi.ssr_kids_wsiblings_long nodupkey ;
	by hun sibssn;
run;

* COLLAPSE TO HUN LEVEL TO GET NUMBER OF SIBLINGS ON PROGRAM AND 
	SUM OF ALL SIBLING SSI PAYMENTS IN EACH YEAR;

proc means noprint data=manasi.ssr_kids_wsiblings_long;
	by hun;
	var n_combpay_1983-n_combpay_2012 n_onssi_1983-n_onssi_2012;
	output out=manasi.ssr_kids_wsibstats
		sum(n_combpay_1983-n_combpay_2012 n_onssi_1983-n_onssi_2012) =
		n_combpay_1983-n_combpay_2012 n_onssi_1983-n_onssi_2012;
run;

data manasi.ssr_kids_wsibstats;
	set manasi.ssr_kids_wsibstats;

	drop _type_;

	* Inflate sibling payments to 2012 dollars;
	n_cpi_1983=2.30;
	n_cpi_1984=2.21;
	n_cpi_1985=2.13;
	n_cpi_1986=2.09;
	n_cpi_1987=2.03;
	n_cpi_1988=1.94;
	n_cpi_1989=1.86;
	n_cpi_1990=1.76;
	n_cpi_1991=1.69;
	n_cpi_1992=1.64;
	n_cpi_1993=1.59;
	n_cpi_1994=1.55;
	n_cpi_1995=1.51;
	n_cpi_1996=1.47;
	n_cpi_1997=1.43;
	n_cpi_1998=1.41;
	n_cpi_1999=1.38;
	n_cpi_2000=1.34;
	n_cpi_2001=1.3;
	n_cpi_2002=1.28;
	n_cpi_2003=1.25;
	n_cpi_2004=1.22;
	n_cpi_2005=1.18;
	n_cpi_2006=1.14;
	n_cpi_2007=1.11;
	n_cpi_2008=1.07;
	n_cpi_2009=1.07;
	n_cpi_2010=1.06;
	n_cpi_2011=1.02;
	n_cpi_2012=1;

	array cpi(1983:2012) n_cpi_1983-n_cpi_2012;
	array combpay(1983:2012) n_combpay_1983-n_combpay_2012;

	do i = 1983 to 2012;
		combpay(i) = combpay(i)*cpi(i);
	end;

	drop n_cpi_:;

	rename 	_freq_=numsib_ever
			n_combpay_1983=n_sibpayall_1983
			n_combpay_1984=n_sibpayall_1984
			n_combpay_1985=n_sibpayall_1985
			n_combpay_1986=n_sibpayall_1986
			n_combpay_1987=n_sibpayall_1987
			n_combpay_1988=n_sibpayall_1988
			n_combpay_1989=n_sibpayall_1989
			n_combpay_1990=n_sibpayall_1990
			n_combpay_1991=n_sibpayall_1991
			n_combpay_1992=n_sibpayall_1992
			n_combpay_1993=n_sibpayall_1993
			n_combpay_1994=n_sibpayall_1994
			n_combpay_1995=n_sibpayall_1995
			n_combpay_1996=n_sibpayall_1996
			n_combpay_1997=n_sibpayall_1997
			n_combpay_1998=n_sibpayall_1998
			n_combpay_1999=n_sibpayall_1999
			n_combpay_2000=n_sibpayall_2000
			n_combpay_2001=n_sibpayall_2001
			n_combpay_2002=n_sibpayall_2002
			n_combpay_2003=n_sibpayall_2003
			n_combpay_2004=n_sibpayall_2004
			n_combpay_2005=n_sibpayall_2005
			n_combpay_2006=n_sibpayall_2006
			n_combpay_2007=n_sibpayall_2007
			n_combpay_2008=n_sibpayall_2008
			n_combpay_2009=n_sibpayall_2009
			n_combpay_2010=n_sibpayall_2010
			n_combpay_2011=n_sibpayall_2011
			n_combpay_2012=n_sibpayall_2012
			n_onssi_1983=n_sibnumon_1983
			n_onssi_1984=n_sibnumon_1984
			n_onssi_1985=n_sibnumon_1985
			n_onssi_1986=n_sibnumon_1986
			n_onssi_1987=n_sibnumon_1987
			n_onssi_1988=n_sibnumon_1988
			n_onssi_1989=n_sibnumon_1989
			n_onssi_1990=n_sibnumon_1990
			n_onssi_1991=n_sibnumon_1991
			n_onssi_1992=n_sibnumon_1992
			n_onssi_1993=n_sibnumon_1993
			n_onssi_1994=n_sibnumon_1994
			n_onssi_1995=n_sibnumon_1995
			n_onssi_1996=n_sibnumon_1996
			n_onssi_1997=n_sibnumon_1997
			n_onssi_1998=n_sibnumon_1998
			n_onssi_1999=n_sibnumon_1999
			n_onssi_2000=n_sibnumon_2000
			n_onssi_2001=n_sibnumon_2001
			n_onssi_2002=n_sibnumon_2002
			n_onssi_2003=n_sibnumon_2003
			n_onssi_2004=n_sibnumon_2004
			n_onssi_2005=n_sibnumon_2005
			n_onssi_2006=n_sibnumon_2006
			n_onssi_2007=n_sibnumon_2007
			n_onssi_2008=n_sibnumon_2008
			n_onssi_2009=n_sibnumon_2009
			n_onssi_2010=n_sibnumon_2010
			n_onssi_2011=n_sibnumon_2011
			n_onssi_2012=n_sibnumon_2012;

	label _freq_='Number of siblings ever on program';

run;
